home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
PASCAL
/
1463.ZIP
/
DRAW-2D.ARC
/
PTDIST.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1986-11-13
|
2KB
|
50 lines
PROCEDURE PTDIST(PX,PY,XONE,YONE:REAL; VAR DIST:REAL);
BEGIN
DIST := SQRT( (XONE-PX)*(XONE-PX) + (YONE-PY)*(YONE-PY) );
END;
PROCEDURE LNDIST(PX,PY,XONE,YONE,XTWO,YTWO:REAL; VAR DIST:REAL);
VAR
REGION:INTEGER;
B1,D1,D2,D3:REAL;
BEGIN
D1 := SQRT( (XONE-PX)*(XONE-PX) + (YONE-PY)*(YONE-PY) );
D2 := SQRT( (XTWO-PX)*(XTWO-PX) + (YTWO-PY)*(YTWO-PY) );
D3 := SQRT( (XONE-XTWO)*(XONE-XTWO) + (YONE-YTWO)*(YONE-YTWO) );
(* DETERMINE THE REGION *)
IF D1 > D2 THEN
IF D1 >= SQRT( (D2*D2) + (D3*D3) ) THEN REGION := 3 ELSE REGION := 2
ELSE
IF D2 >= SQRT( (D1*D1) + (D3*D3) ) THEN REGION := 1 ELSE REGION := 2;
CASE REGION OF
1: DIST := D1;
2: BEGIN
B1 := ( (D1*D1) - (D2*D2) + (D3*D3) )/(2.0*D3);
DIST := SQRT( (D1*D1) - (B1*B1) );
END;
3: DIST := D2;
END; (*CASE*)
END;
PROCEDURE CIRDIST(PX,PY,XONE,XTWO,RAD:REAL; VAR DIST:REAL);
VAR
DX:REAL;
BEGIN
PTDIST(PX,PY,XONE,XTWO,DX);
DIST := ABS(DX-RAD);
END;
PROCEDURE BXDIST(PX,PY,X1,Y1,X2,Y2,X3,Y3:REAL; VAR DIST:REAL);
VAR
X4,Y4,D1,D2,D3,D4:REAL;
BEGIN
X4 := X3 - (X2-X1);
Y4 := Y3 - (Y2-Y1);
LNDIST(PX,PY,X1,Y1,X2,Y2,D1);
LNDIST(PX,PY,X2,Y2,X3,Y3,D2);
LNDIST(PX,PY,X3,Y3,X4,Y4,D3);
LNDIST(PX,PY,X4,Y4,X1,Y1,D4);
DIST := ABS(XWMAX-XWMIN);
IF DIST > D1 THEN DIST := D1;
IF DIST > D2 THEN DIST := D2;
IF DIST > D3 THEN DIST := D3;
IF DIST > D4 THEN DIST := D4;
END;